Shell脚本实战28-Nginx负载节点状态检测 发表于 2018-03-05 | 更新于: 2018-03-25 | 分类于 Shell 开发通过Web界面展示监控Nginx代理节点的状态。当节点宕机时,以红色展示,当节点正常时以绿色展示。 这个脚本要求对Nginx服务很熟练,由于我的水平不够,所以仅以摘抄的方式收录了这个脚本。 Shell脚本如下:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768#!/bin/bashRIPS=( 10.0.0.7 10.0.0.8 )file_location=/var/html/test.html[ -e "file_location" ] || mkdir `dirname $file_location` -pfunction web_result(){ rs=`curl -I -s $1 | awk 'NR==1{print $2}'` return $rs}function new_row(){ cat >> $file_location <<eof <tr> <td bgcolor="$4">$1</td> <td bgcolor="$4">$2</td> <td bgcolor="$4">$3</td> </tr> eof}function auto_html(){ web_result $2 rs=$? if [ $rs -eq 200 ] then new_row $1 $2 up green else new_row $1 $2 down red fi}function main(){ while true do cat >> $file_location <<eof <h4>Nginx Server Status Of RS :</h4> <meta http-equiv="refresh" content="1"> <table border="1"> <tr> <th>NO:</th> <th>IP:</th> <th>Status:</th> </tr> eof for ((i=0; i<${#RIPS[*]}; i++)) do auto_html $i ${RIPS[$i]} done cat >> $file_location <<eof </table> eof sleep 2 > $file_location done}main $*